<template>
  <div class="app-container">
    <div class="filter-container">
      <el-card>
        <el-form ref="searchform" :inline="true" :model="searchform" class="demo-form-inline" size="small">
          <el-form-item label="代理人：">
            <el-input v-model="searchform.UserName" clearable placeholder="代理人" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <el-card>
      <div class="list-btn-container">
        <el-button-group>
          <slot v-for="itemf in loadBtnFunc">
            <el-button v-if="itemf.FullName==='新增'" type="default" icon="el-icon-plus" size="small" @click="ShowEditOrViewDialog()">新增</el-button>
            <el-button v-if="itemf.FullName==='修改'" type="default" icon="el-icon-edit" size="small" @click="ShowEditOrViewDialog('edit')">修改</el-button>
            <el-button v-if="itemf.FullName=='下架'" type="default" icon="el-icon-video-pause" size="small" @click="SetOnState('0')">下架</el-button>
            <el-button v-if="itemf.FullName=='上架'" type="default" icon="el-icon-video-play" size="small" @click="setEnable('1')">上架</el-button>
            <el-button v-if="itemf.FullName==='软删除'" type="default" icon="el-icon-delete" size="small" @click="deleteSoft('0')">软删除</el-button>
            <el-button v-if="itemf.FullName==='删除'" type="default" icon="el-icon-delete" size="small" @click="deletePhysics()">删除</el-button>
            <el-button v-if="itemf.FullName==='重置密码'" type="default" icon="el-icon-refresh-right" size="small" @click="handleResetPassword()">重置密码</el-button>
          </slot>
          <el-button type="default" icon="el-icon-refresh" size="small" @click="loadTableData()">刷新</el-button>
        </el-button-group>
      </div>
      <el-table
        ref="gridtable"
        v-loading="tableloading"
        :data="tableData"
        border
        stripe
        highlight-current-row
        style="width: 100%"
        :default-sort="{prop: 'SortCode', order: 'descending'}"
        @select="handleSelectChange"
        @select-all="handleSelectAllChange"
        @sort-change="handleSortChange"
      >
        <el-table-column
          prop="Id"
          label="云库存编码"
          width="100"
          fixed
        />
        <el-table-column
          prop="GoodsDto.Title"
          label="商品"
          width="200"
          fixed
        />
        <el-table-column
          prop="GoodsDto.GoodsSpecDtos[0].Name"
          label="规格"
          sortable="custom"
          width="150"
          fixed
        />
        <el-table-column
          prop="UserName"
          label="代理"
          width="100"
          fixed
        />
        <el-table-column
          prop="UserId"
          label="代理编码"
          width="100"
          align="center"
        />
        <el-table-column
          prop="TotalBuyNum"
          label="总购买数量"
          width="150"
          align="center"
        />
        <el-table-column
          prop="TotalUseNum"
          label="消耗数量"
          width="150"
          align="center"
        />
        <el-table-column
          prop="Num"
          label="库存"
          width="180"
          align="center"
        />
        />

      </el-table>
      <div class="pagination-container">
        <el-pagination
          background
          :current-page="pagination.currentPage"
          :page-sizes="[5,10,20,50,100, 200, 300, 400]"
          :page-size="pagination.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.pageTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

  </div>
</template>

<script>

import { getPage } from '@/api/shop/cloudstock'
import defaultSettings from '@/settings'
import * as fecha from 'element-ui/lib/utils/date'
export default {
  data() {
    return {
      StatusOptions: [{
        value: '1',
        label: '待支付'
      }, {
        value: '2',
        label: '已支付'
      }, {
        value: '3',
        label: '支付失败'
      }, {
        value: '4',
        label: '支付取消'
      }],
      IsDisabled: false,
      activeName: 'first',
      editorOption: {
        placeholder: '请输入...',
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'], // 加粗，斜体，下划线，删除线
            ['blockquote', 'code-block'], // 引用，代码块

            [{ 'header': 1 }, { 'header': 2 }], // 标题，键值对的形式；1、2表示字体大小
            [{ 'list': 'ordered' }, { 'list': 'bullet' }], // 列表
            [{ 'script': 'sub' }, { 'script': 'super' }], // 上下标
            [{ 'indent': '-1' }, { 'indent': '+1' }], // 缩进
            [{ 'direction': 'rtl' }], // 文本方向

            [{ 'size': ['small', false, 'large', 'huge'] }], // 字体大小
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }], // 几级标题

            [{ 'color': [] }, { 'background': [] }], // 字体颜色，字体背景颜色
            [{ 'font': [] }], // 字体
            [{ 'align': [] }], // 对齐方式

            ['clean'], // 清除字体样式
            ['image', 'video'] // 上传图片、上传视频

          ]
        },
        theme: 'snow'
      },
      content: '',
      searchform: {
        UserName: ''
      },
      selectRole: [],
      selectedOrganizeOptions: '',
      selectOrganize: [],
      SysLogo: '',
      loadBtnFunc: [],
      tableData: [],
      tableloading: true,
      pagination: {
        currentPage: 1,
        pagesize: 10,
        pageTotal: 0
      },
      sortableData: {
        // order: '',
        // sort: ''
      },
      dialogEditFormVisible: false,
      editFormTitle: '',
      editFrom: {
        Account: '',
        RealName: '',
        NickName: '',
        Gender: '1',
        Birthday: '',
        MobilePhone: '',
        Email: '',
        WeChat: '',
        OrganizeId: '',
        RoleId: '',
        IsAdministrator: true,
        EnabledMark: true,
        Description: ''
      },
      rules: {
        Title: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 16 个字符', trigger: 'blur' }
        ],
        EnCode: [
          { required: true, message: '请输入识别码', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ]
      },
      httpFileUploadUrl: defaultSettings.fileUploadUrl,
      dialogVisible: false,
      dialogImageUrl: '',
      filelist: [],
      formLabelWidth: '150px',
      currentId: '',
      currentSelected: []
    }
  },
  created() {
    this.pagination.currentPage = 1
    // this.InitDictItem()
    this.loadTableData()
    this.loadBtnFunc = JSON.parse(localStorage.getItem('yueboncurrentfuns'))
  },
  methods: {
    InitDictItem() {
    },

    loadTableData: function() {
      this.tableloading = true
      var seachdata = {
        'CurrenetPageIndex': this.pagination.currentPage,
        'PageSize': this.pagination.pagesize,
        'UserName': this.searchform.UserName
      }
      getPage(seachdata).then(res => {
        this.tableData = res.ResData.Items
        this.pagination.pageTotal = res.ResData.TotalItems
        this.tableloading = false
      })
    },
    handleSearch: function() {
      this.pagination.currentPage = 1
      this.loadTableData()
    },
    handleRemove(file, fileList) {
      this.editFrom.SysLogo = file.url
    },
    handleSizeChange(val) {
      this.pagination.pagesize = val
      this.pagination.currentPage = 1
      this.loadTableData()
    },
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.loadTableData()
    }
  }
}
</script>
